package com.example.admin.controller.tijiaodaan;

import com.example.candiates.service.CandidateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/candidate")
public class CandidateController {

    private static final Logger log = LoggerFactory.getLogger(CandidateController.class);

    private final CandidateService candidateService;

    public CandidateController(CandidateService candidateService) {
        this.candidateService = candidateService;
    }

    @GetMapping("/interview/{candidateId}")
    public Map<String, Object> getInterviewDetails(@PathVariable Integer candidateId) {
        log.info("开始获取面试详情，候选人ID: {}", candidateId);
        return candidateService.getInterviewDetails(candidateId);
    }

    @PostMapping("/interview/answer/{candidateId}")
    public Map<String, Object> submitAnswer(@PathVariable Integer candidateId, @RequestBody Map<String, Object> body) {
        Integer questionId = (Integer) body.get("questionId");
        String answer = (String) body.get("answer");
        boolean success = candidateService.submitAnswer(candidateId, questionId, answer);
        Map<String, Object> result = new java.util.HashMap<>();
        if (success) {
            result.put("code", 200);
            result.put("msg", "提交成功");
        } else {
            result.put("code", 500);
            result.put("msg", "提交答案失败");
        }
        return result;
    }
} 